// VBConversions Note: VB project level imports
using System.Data;
using DevExpress.XtraEditors.Controls;
using System.Diagnostics;
using System.Xml.Linq;
using DevExpress.XtraEditors.Repository;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.VisualBasic;
using System.Configuration;
using System.Collections;
using DevExpress.XtraEditors;
using System.Data.Sql;
using Microsoft.SqlServer;
using System.Windows.Forms;
using System;
using DevExpress.XtraReports;
using Microsoft.SqlServer.Management.Smo;
using DevExpress;
using System.Linq;
using System.IO;
// End of VB project level imports


namespace SCIEF.SysBFW.CommonExt
{
	public class MetaList : IDisposable
	{
		
		private bool disposedValue = false; // To detect redundant calls
		private MetaListValues _metaListValues = new MetaListValues();
		private MetaQuery mq;
		private string _filter;
		
#region  Property Field
		private string _listCd;
		private string _listDescr_PRM;
		private string _listDescr_ALT;
		private Guid _listId;
		private bool _inactive;
		private bool _readonly;
#endregion
		/// <summary>
		/// MetaList classe that contains, all the value and the description of the list.
		/// </summary>
		/// <param name="listName"></param>
		/// <param name="filter "></param>
		/// <remarks>Populate by the MetaCommand Metalists</remarks>
		public MetaList(string listName, string filter = null)
		{
			this._listCd = listName;
			this._filter = filter;
			this.FillMetaListInfo();
			this.FillMetaListValues();
		}
		
		public void FillMetaListInfo()
		{
			//mq = MetaQuery.GetMetaQueryByName("MetaLists", "Meta")
			mq = MetaQuery.GetMetaQueryByName("MetaLists");
			mq.SQLWhere = string.Format("ListCd = \'{0}\'", this.ListCd);
			if (this.Filter != null)
			{
				mq.SQLWhereContext = this.Filter;
			}
			mq.FillResultQuery();
			foreach (DataRow row in mq.ResultQuery.Rows)
			{
				this.Inactive = System.Convert.ToBoolean(row["Inactive"]);
				this.ListId = (Guid) (row["ListID"]);
				this.ListCd = row["ListCd"].ToString();
				this.ListDescr_ALT = row["ListDescr_ALT"].ToString();
				this.ListDescr_PRM = row["ListDescr_PRM"].ToString();
				this.Readonly = System.Convert.ToBoolean(row["Readonly"]);
			}
		}
		public void FillMetaListValues()
		{
			MetaListValue mlv = default(MetaListValue);
			//Dim gid As Guid
			
			//mq = MetaQuery.GetMetaQueryByName("MetaListValues", "Meta")
			mq = MetaQuery.GetMetaQueryByName("MetaListValues");
			mq.SQLWhere = string.Format("ListID_FK = \'{0}\'", this.ListId);
			if (this.Filter != null)
			{
				mq.SQLWhereContext = this.Filter;
			}
			mq.FillResultQuery();
			foreach (DataRow row in mq.ResultQuery.Rows)
			{
				mlv = new MetaListValue();
				mlv.Inactive = System.Convert.ToBoolean(row["Inactive"]);
				mlv.ListOrder = System.Convert.ToInt32(row["ListOrder"]);
				mlv.ListValueCd = row["ListValueCd"].ToString();
				mlv.ListValueDescr_ALT = row["ListValueDescr_ALT"].ToString();
				mlv.ListValueDescr_PRM = row["ListValueDescr_PRM"].ToString();
				mlv.ListValueID = (Guid) (row["ListValueID"]);
				//gid = New Guid(row("ListValueID").ToString)
				if (!this._metaListValues.ContainsKey(mlv.ListValueID))
				{
					this._metaListValues.Add(mlv.ListValueID, mlv);
				}
			}
			
		}
		public bool Readonly
		{
			get
			{
				return _readonly;
			}
			set
			{
				_readonly = value;
			}
		}
		public bool Inactive
		{
			get
			{
				return _inactive;
			}
			set
			{
				_inactive = value;
			}
		}
		public string ListCd
		{
			get
			{
				return _listCd;
			}
			set
			{
				_listCd = value;
			}
		}
		public string ListDescr_ALT
		{
			get
			{
				return _listDescr_ALT;
			}
			set
			{
				_listDescr_ALT = value;
			}
		}
		public string ListDescr_PRM
		{
			get
			{
				return _listDescr_PRM;
			}
			set
			{
				_listDescr_PRM = value;
			}
		}
		public string Filter
		{
			get
			{
				return _filter;
			}
			set
			{
				_filter = value;
			}
		}
		public Guid ListId
		{
			get
			{
				return _listId;
			}
			set
			{
				_listId = value;
			}
		}
		public MetaListValues MetaListValues
		{
			get
			{
				return _metaListValues;
			}
		}
		
		// IDisposable
		protected virtual void Dispose(bool disposing)
		{
			if (!this.disposedValue)
			{
				if (disposing)
				{
					// TODO: free other state (managed objects).
					_metaListValues = null;
					mq = null;
				}
				// TODO: free your own state (unmanaged objects).
				// TODO: set large fields to null.
			}
			this.disposedValue = true;
		}
		
#region  IDisposable Support
		// This code added by Visual Basic to correctly implement the disposable pattern.
		public void Dispose()
		{
			// Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
			Dispose(true);
			GC.SuppressFinalize(this);
		}
#endregion
		
	}
	
	public class MetaListValue
	{
		
#region  Property Field
		private Guid _listValueID;
		private string _listValueCd;
		private string _listValueDescr_PRM;
		private string _listValueDescr_ALT;
		private int _listOrder;
		private bool _inactive;
		private bool _readonly;
#endregion
		
#region  Property
		public bool Readonly
		{
			get
			{
				return _readonly;
			}
			set
			{
				_readonly = value;
			}
		}
		public bool Inactive
		{
			get
			{
				return _inactive;
			}
			set
			{
				_inactive = value;
			}
		}
		public int ListOrder
		{
			get
			{
				return _listOrder;
			}
			set
			{
				_listOrder = value;
			}
		}
		public string ListValueCd
		{
			get
			{
				return _listValueCd;
			}
			set
			{
				_listValueCd = value;
			}
		}
		public string ListValueDescr_ALT
		{
			get
			{
				return _listValueDescr_ALT;
			}
			set
			{
				_listValueDescr_ALT = value;
			}
		}
		public string ListValueDescr_PRM
		{
			get
			{
				return _listValueDescr_PRM;
			}
			set
			{
				_listValueDescr_PRM = value;
			}
		}
		public Guid ListValueID
		{
			get
			{
				return _listValueID;
			}
			set
			{
				_listValueID = value;
			}
		}
#endregion
		
		
	}
	
	/// <summary>
	/// Dictionnary collection of MetaValues
	/// </summary>
	/// <remarks>Populate by the MetaCommand MetalistValues. Dictionnary collection have been use cause is more effecient for Lookup process</remarks>
	public class MetaListValues : System.Collections.Generic.Dictionary<Guid, MetaListValue>
	{
		
	}
	
	
	
	
	
	
	
	
	
}
